<?
$PATHTOMUSIC = 'http://71.6.195.82/music/';
include('db.php');
if (isset($_GET['playlist']))
{
    $id = (int) $_GET['playlist'];
    $query = 'SELECT songidlist FROM playlists WHERE playlistid = ' . $id;
    $result = mysql_query($query) or die(mysql_error());
    $arr = array();
    if (mysql_affected_rows() != 0)
    {
        $row = mysql_fetch_row($result);
        $songidlist = $row[0];
        $songids = explode(',', $songidlist);
        foreach ($songids as $id){
            $query = 'SELECT title,extension FROM songlist WHERE songid = ' . $id;
            $result = mysql_query($query) or die(mysql_error());
            if (mysql_affected_rows() != 0)
            {
                $row = mysql_fetch_row($result);
                $title = $row[0];
                $ext = $row[1];
                $arr[] = $PATHTOMUSIC . $title . '.' . $ext;
            }
        }
    }
}
else
{
    $limit = $_GET['jukebox'];
    $query = 'SELECT title,extension FROM songlist';
    $result = mysql_query($query) or die(mysql_error());
    $arr = array();
    while ($row = mysql_fetch_array($result,MYSQL_ASSOC))
    {
        $title = $row['title'];
        $ext = $row['extension'];
        $arr[] = $PATHTOMUSIC . $title . '.' . $ext;
    }
    shuffle($arr);
    $arr = array_slice($arr, 0, $limit);
}
echo implode("\n",$arr);
?>